package ast;

import parser.UnaryOperatorType;
import lexer.Position;

public class UnaryOperatorNode extends ExpressionNode {

	public ExpressionNode getRight() {
		return right;
	}

	public UnaryOperatorType getOp() {
		return op;
	}

	private final UnaryOperatorType op;
	private final ExpressionNode right;

	public UnaryOperatorNode(Position position, ExpressionNode right, UnaryOperatorType op) {
		super(position, right);
		this.op = op;
		this.right = right;
	}

	@Override
	public String toString() {
		return "UnaryOperatorNode [op=" + op + ", right=" + right + "]";
	}
	
	public long collapseExp() throws Exception {
		switch (this.op){
		case PLUS: return this.right.collapseExp();
		case MINUS: return 0L - this.right.collapseExp();
		default: throw new Exception("not recognized operator: " + op.toString());
		}
	}

}
